﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace TSCL.Web.users
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int id=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(id);
				}
			}
		}
			
	private void ShowInfo(int id)
	{
		TSCL.BLL.users bll=new TSCL.BLL.users();
		TSCL.Model.users model=bll.GetModel(id);
		this.lblid.Text=model.id.ToString();
		this.txtusercode.Text=model.usercode;
		this.txtuserpwd.Text=model.userpwd;
		this.txtusername.Text=model.username;
		this.txtphone.Text=model.phone;
		this.txtemail.Text=model.email;
		this.txtisuse.Text=model.isuse.ToString();
		this.txtremarks.Text=model.remarks;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtusercode.Text.Trim().Length==0)
			{
				strErr+="usercode不能为空！\\n";	
			}
			if(this.txtuserpwd.Text.Trim().Length==0)
			{
				strErr+="userpwd不能为空！\\n";	
			}
			if(this.txtusername.Text.Trim().Length==0)
			{
				strErr+="username不能为空！\\n";	
			}
			if(this.txtphone.Text.Trim().Length==0)
			{
				strErr+="phone不能为空！\\n";	
			}
			if(this.txtemail.Text.Trim().Length==0)
			{
				strErr+="email不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtisuse.Text))
			{
				strErr+="isuse格式错误！\\n";	
			}
			if(this.txtremarks.Text.Trim().Length==0)
			{
				strErr+="remarks不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int id=int.Parse(this.lblid.Text);
			string usercode=this.txtusercode.Text;
			string userpwd=this.txtuserpwd.Text;
			string username=this.txtusername.Text;
			string phone=this.txtphone.Text;
			string email=this.txtemail.Text;
			int isuse=int.Parse(this.txtisuse.Text);
			string remarks=this.txtremarks.Text;


			TSCL.Model.users model=new TSCL.Model.users();
			model.id=id;
			model.usercode=usercode;
			model.userpwd=userpwd;
			model.username=username;
			model.phone=phone;
			model.email=email;
			model.isuse=isuse;
			model.remarks=remarks;

			TSCL.BLL.users bll=new TSCL.BLL.users();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
